'use strict';
const requireEx = require('yi-require');

module.exports = {
    open: false,
    description: '优惠券核销',
    handler(req, res, next) {
        let doc = req.body;
        req.mongo.collection('coupon').updateOne({number: doc.number}, {$set: {writeOff: true}}, (e0, r0) => {
            if (e0) return res.err.mongoError(e0);
            if (r0.modifiedCount===1) {
                return res.reply({code: 0, message: "优惠券核销成功！"});
            } else {
                return res.reply({code: 1, message: "券码错误或优惠券已核销！"});
            }
        });
    }
};
